var pdpPage = avalon.define({
	$id: "pdpPage",
	email:"",
	content:"",
	solution: {
		title: "",
		description1: "",
		description2: "",
		overview: "",
		solutionItems: []
	},
	validateSendMail: {
		onValidateAll: function(reasons) {
			if(reasons.length) {
				mui.toast(reasons[0].getMessage());
			} else {
				var form=$("#sendMailForm");
				mui.ajax('/mail/send.do', {
					data: form.serialize(),
					dataType: 'json',
					type:'post',
					success: function(data) {
						 mui('#emailShare').popover('hide');
						 mui.alert("",data.msg);
						 pdpPage.content="";
						 pdpPage.email="";
					}
				});

			}
		}

	},
	sendMail: function(e) {
		e.preventDefault()
		this.validateSendMail.onManual();
	}

});

mui.ready(function() {
	var sid = $.getParameter("sid");
	var mui_pdp = mui('#pdp');
	mui.init({
		pullRefresh: {
			container: "#pdp",
			down: {
				height: 50,
				auto: true,
				contentdown: $.i18n.contentDown,
				contentover: $.i18n.contentOver,
				contentrefresh: $.i18n.contentRefresh,
				callback: function() {
					setTimeout(function() {
						mui.ajax('/solution/pdp.json', {
							data: {
								sid: sid
							},
							dataType: 'json',
							success: function(data) {
								pdpPage.solution = data;
								mui_pdp.pullRefresh().endPulldownToRefresh();

							}
						});
					}, window.DAHUA_CONFIG.LOADING_TIME);

				}
			}
		}
	});

	//收藏
	mui('.header').on('tap', '.collection', function(e) {
		var uid = $("#uid").val();
		if("" == uid) {
			mui.openWindow({
				url: "dahua://login"
			});
			return false;
		}
		mui.ajax('/solution/collect.do', {
			data: {
				sid: sid,
				uid: uid
			},
			dataType: 'json',
			success: function(data) {
				mui.alert(data.msg, " ");
			}
		});

	});
	mui.previewImage();
	
	mui(".shares").on('tap', '.whatsapp', function() {
		var btnArray = ['Cancel', 'OK'];
		mui.confirm('Would like to share the solution?', '', btnArray, function(e) {
			if(e.index == 1) {
				var text = $("#shareTitle").val();
				var img = $("#img").val();
				location.href = "dahua://openShare?text=" + text + "&&img=" + img;
			}
		})
	});
	

});